package cn.edu.hpu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.hpu.dao.DealDao;
import cn.edu.hpu.pojo.Deal;


public class DealService {
	private DealDao dealDao;
	
	public List<Deal> findByTitle(String title){
		return dealDao.findBy("title", title);
	}
	
	
	@Autowired
	public void setDealDao(DealDao dealDao) {
		this.dealDao = dealDao;
	}


	public List<Deal> findByAll() {
		
		return dealDao.findAll();
	}

	public Deal findById(String id) {
		Deal d = dealDao.get(id);
		if(d!=null){
			return d;
		}else{
			return null;
		}
		
	}

	public void delete(String id) {
		dealDao.del(id);
		
	}
	public void save(Deal deal) {
		dealDao.save(deal);
		
	}


	public List<Deal> findByProperty(String property, String value) {
		
		return dealDao.findBy(property, value);
	}


	public void update(Deal d) {
		dealDao.update(d);
		
	}
	
	public long dcount(String userid){
		String hql = "select count(*) from Deal where userid=?";
		Object object = dealDao.findUnique(hql, userid);
		return (Long)object;
	}
}
